﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;

/// <summary>
///DBHelper 的摘要说明
/// </summary>

public class DBHelper
{
    public DBHelper() { }
    public static string connectionString = ConfigurationManager.ConnectionStrings["DB"].ConnectionString;
    /// <summary>
    /// 执行一条SQL语句 返回 DataTable
    /// </summary>
    /// <param name="text"></param>
    /// <returns></returns>
    public static DataTable GetDataTable(string text)
    {
        SqlConnection conn = new SqlConnection(connectionString);
        conn.Open();

        SqlDataAdapter odda = new SqlDataAdapter(text, conn);

        DataSet ds = new DataSet();
        odda.Fill(ds);
        conn.Close();
        return ds.Tables[0];
    }

    /// <summary>
    /// 执行一条SQL语句 返回影响行数
    /// </summary>
    /// <param name="text"></param>
    /// <returns></returns>
    public static int ExecuteCommand(string text)
    {
        SqlConnection conn = new SqlConnection(connectionString);
        conn.Open();
        SqlCommand cmd = new SqlCommand(text, conn);
        int i = cmd.ExecuteNonQuery();
        conn.Close();
        return i;
    }
}